package com.shunhao.utils

import android.text.TextUtils
import com.blankj.utilcode.util.SPUtils
import java.util.*

/**
 * UUID utils
 * @author kgy
 */
object UuidUtils {

    private const val SP_KEY = "UUID"
    private const val BASE_UUID = "abcdefghijklmnopqrstuvwxyz0123456789"
    private const val UUID_LENGTH = 32

    /**
     * @功能说明： 获取随机字符串32位
     * @author: kgy
     */
    private val uUid: String
        get() {
            val random = Random()
            val sb = StringBuffer()
            for (i in 0 until UUID_LENGTH) {
                val number = random.nextInt(BASE_UUID.length)
                sb.append(BASE_UUID[number])
            }
            SPUtils.getInstance().put(SP_KEY, sb.toString())
            return sb.toString()
        }

    /**
     * @author kgy
     * @description 获取唯一UUID
     * @date 2019-10-27 12:41
     */
    val onlyUUid: String
        get() {
            val uuid: String
            val saveUuid = SPUtils.getInstance().getString(SP_KEY, "")
            uuid = if (TextUtils.isEmpty(saveUuid)) {
                uUid
            } else {
                saveUuid
            }
            return uuid
        }
}